#include <iostream>
#include <cstring>

#define NAMESIZE 32

using namespace std;

class Person {
    private:
        int id;
        char name[NAMESIZE];

    public:
        Person(int id, const char *name): id(id) {strncpy(this->name, name, NAMESIZE);}
        virtual void show() {cout << id << " " << name << endl;}
        int getId() const {return id;} 
        const char *getName() const {return (const char *)name;}
};

class Student : public Person {
    private:
        float score;

    public:
        Student(int id, const char *name, float score);
        void show() {cout << getId() << " " << getName() << " " << score << endl;}
};


Student::Student(int id, const char *name, float score): Person(id, name)
{
    //this->id = id; // 不能用此方式赋值
    //id = id;
    this->score = score;
}

int main(void)
{
	Student s1(1, "派生类对象", 90);
	Person p1(2, "基类对象");
	Person *p;

	// s1.id = 1;
	// strncpy(s1.name, "继承", NAMESIZE);

	s1.Person::show();
	s1.show();

	p = &p1;
	p->show();
	p = &s1;
	p->show(); //?????????? 应该调用的学生对象的show方法

	return 0;
}

